package com.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.PestBean;
import com.project.service.PestService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/pest")
public class PestController {

    @Resource
    private PestService pestService;


    //显示所有虫害
    @RequestMapping("/findAllPest")
    @ResponseBody
    public IPage<PestBean> findAllPest(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                       @RequestParam(value = "pageSize", defaultValue = "2") int pageSize) {
        return pestService.findAllPest(pageNo, pageSize);
    }

    //添加新虫害
    @RequestMapping("/addPest")
    @ResponseBody
    public String addPest(PestBean pestBean) {
        pestService.addPest(pestBean);
        return "ok";
    }


    //查看详细信息
    @RequestMapping("/findId")
    @ResponseBody
    public PestBean findId(int pestId) {
        return pestService.findId(pestId);
    }

    //模糊查询
    @RequestMapping("/findName")
    @ResponseBody
    public IPage<PestBean> findName(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                    @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
                                    String pestName, String pestHost) {
        return pestService.findName(pageNo, pageSize, pestName, pestHost);
    }
}
